﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using UraniaLib;


namespace SkyPoint
{
    public class PlanetUtils
    {
        UraniaPlanetData planetData;
        UraniaMoonData moonData;
        UraniaSunData sunData;

        public string[] PlanetNames { get; private set; }
        public double[] PlanetMagnitudes { get; private set; }

        public PlanetUtils()
        {
            planetData = new UraniaPlanetData();
            moonData = new UraniaMoonData();
            sunData = new UraniaSunData();
            PlanetNames = new string[] { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" };
            PlanetMagnitudes = new double[] { 0, -1, 0, -1, -1, 0.5, 5.5, 8.0 };    
        }

        public Coord getPlanetCoordinates(int planetSeq, DateTime time)
        {
            double decl = 0; double rA = 0;
            bool inner;
            if(planetSeq < 3) inner = true;
            else inner = false;
            
            UraniaPlanet.CalcPlanetCoord(planetData.dEpoch, time,
                                         planetData.fPeriod[planetSeq],
                                         planetData.fEcc[planetSeq],
                                         planetData.fEpochLong[planetSeq],
                                         planetData.fPerihelionLong[planetSeq],
                                         planetData.fSMA[planetSeq],
                                         planetData.fAscNode[planetSeq],
                                         planetData.fIncl[planetSeq],
                                         planetData.fPeriod[2],
                                         planetData.fEcc[2],
                                         planetData.fEpochLong[2],
                                         planetData.fPerihelionLong[2],
                                         planetData.fSMA[2],
                                         inner, ref rA, ref decl);
            return new Coord(rA, decl);
        }

        public Coord getMoonCoordinates(DateTime time)
        {
            double decl = 0; double rA = 0;
            UraniaMoon.CalcMoonPos(time, moonData.dEpoch,
                                   moonData.fMeanEpochLong,
                                   moonData.fMeanPeriLong,
                                   moonData.fAscNode,
                                   moonData.fIncl,
                                   moonData.fEcc,
                                   sunData.fEpochEclLong,
                                   sunData.fPeriEclLong,
                                   sunData.fEcc,
                                   ref rA, ref decl);
            return new Coord(rA,decl);
        }
    }
}
